<template>
  <div class="container">
    <el-dialog
      title="题目审核"
      :visible="dialogChkState"
      width="20%"
      @close="setShow"
    >
      <el-form>
        <el-form-item>
          <el-radio v-model="checkData.chkState" :label="1">通过</el-radio>
          <el-radio v-model="checkData.chkState" :label="2">拒绝</el-radio>
        </el-form-item>
        <el-form-item>
          <el-input
            type="textarea"
            v-model="checkData.chkRemarks"
            placeholder="请输入审核意见"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="setShow">取 消</el-button>
        <el-button type="primary" @click="confirm()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck } from '@/api/hmmm/questions'
export default {
  name: 'QuestionsCheck',
  props: {
    // 接受弹出框的布尔值
    dialogChkState: {
      type: Boolean,
      default: false
    },
    // 接受的内容
    questionInfo: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      checkData: {
        id: null,
        chkState: 1, // 单选框
        chkRemarks: null // 内容
      }
    }
  },
  methods: {
    // 取消操作
    setShow () {
      this.$emit('update:dialogChkState', false)
    },

    // 确认操作
    async confirm () {
      // console.log(1)
      if (!this.checkData.chkRemarks) { return this.$message.warning('请输入审核意见') }
      // 给id 赋值
      this.checkData.id = this.questionInfo.id
      // console.log(this.checkData.id)
      // 发送请求数据
      await choiceCheck(this.checkData)
      this.$message.success('操作成功')
      // 关闭对话框
      this.setShow()
      // 子传父，重新渲染
      this.$emit('updateList')
    }
  }
}
</script>

<style scoped lang="scss"></style>
